package com.yjzx.util.common.util.batch.mergingLimit;

import java.util.Collection;
import java.util.function.BiConsumer;
import java.util.function.Function;

/**
 * @author guozhi
 * @date 2025/1/13
 * @description ParamViewBuilder
 */
public class MergingBuilder<T, U extends Comparable<U>,R>  {
    private T param;
    private Function<T, U> uStartGet;
    private BiConsumer<T, U> uStartSet;
    private Function<T, U> uEndGet;
    private BiConsumer<T, U> uEndSet;
    private final MergingSlotManager<T, U, R> mergingSlotManager;

    MergingBuilder() {
        mergingSlotManager = new MergingSlotManager<>();
    }

    public static<T, U extends Comparable<U>,R> MergingBuilder<T, U,R> paramView() {
        return new MergingBuilder<>();
    }

    public MergingBuilder<T, U ,R> withParam(T param) {
        this.param = param;
        return this;
    }

    public MergingBuilder<T, U,R> withStartGet(Function<T, U> uStartGet) {
        this.uStartGet = uStartGet;
        return this;
    }

    public MergingBuilder<T, U,R> withStartSet(BiConsumer<T, U> uStartSet) {
        this.uStartSet = uStartSet;
        return this;
    }

    public MergingBuilder<T, U,R> withEndGet(Function<T, U> uEndGet) {
        this.uEndGet = uEndGet;
        return this;
    }

    public MergingBuilder<T, U,R> withEndSet(BiConsumer<T, U> uEndSet) {
        this.uEndSet = uEndSet;
        return this;
    }
    public MergingBuilder<T, U,R> withSlot(MergingSlot<T, U, R> uEndSet) {
        this.mergingSlotManager.addSlot(uEndSet);
        return this;
    }

    public MergingBuilder<T, U,R> withSlots(Collection<MergingSlot<T, U, R>> uEndSet) {
        this.mergingSlotManager.addAllSlot(uEndSet);
        return this;
    }

    public MergingView<T,U,R> build() {
        return new MergingView<>(param, uStartGet, uStartSet, uEndGet, uEndSet, mergingSlotManager);
    }

}
